package com.huazi.www.doctor.doctorg.servlet;


import com.huazi.www.doctor.doctorg.service.Totalbillservice;
import com.huazi.www.doctor.doctorg.service.impl.TotalbillServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.awt.*;
import java.io.IOException;
import java.util.ArrayList;

/**
 * 总费用的servlet
 */

public class TotalbillServlet extends HttpServlet {
    /**
     * 得到statistics.jsp的请求
     *
     * @param req
     * @param resp
     * @throws ServletException
     * @throws IOException
     */
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        //new对象
        Totalbillservice service = new TotalbillServiceImpl();

        //得到药品的总收入
        double drugprice = service.drugcost();
        //得到挂号的总收入
        double guahaoprice = service.guahaocost();
        //得到检查的总收入
        double checkprice = service.checkcost();
        //将收入写入数组转发页面
        Double[] arr = new Double[4];
        arr[0] = drugprice;
        arr[1] = guahaoprice;
        arr[2] = checkprice;
        arr[3] = (guahaoprice + checkprice + drugprice);
        req.setAttribute("arr", arr);
        req.getRequestDispatcher("doctor/statistics.jsp").forward(req, resp);
    }

    /**
     * 得到statistics.jsp的请求
     *
     * @param req
     * @param resp
     * @throws ServletException
     * @throws IOException
     */
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }
}
